import React from 'react';
import './BecomeAdminPage.css'
import Header from '../../component/Header/Header';
import Sidebar from '../../component/Sidebar/Sidebar';
import UserTable from '../../component/Table/UserTable'
import UserBlock from '../../component/UserBlock/UserBlock';
import Commentarea from '../../component/Comment/comment'
import { Button, Divider, Typography, Table, Space} from 'antd';
import { useState } from 'react';
import axios from 'axios'

const { Title, Paragraph, Text, Link } = Typography;

function BecomeAdminPage() {
    const request = axios.create({
        baseURL: "http://localhost:8080",
    });
    const become_admin = () => {
      var store = window.localStorage
      const user_name = store.getItem("UserName")
      var username = { "username": user_name } // 传入的参数，使用 json 格式
      request.post("/api/getUser", username).then (  
        res => {  // 成功的回调函数
          console.log(res.data.isAdmin)
          if (res.data.isAdmin == 1) {
            alert("您目前已经是管理员了")
          }
          else {
            request.post("/api/becomeAdmin", username).then (  
                res => {  // 成功的回调函数
                  alert("您成功成为了管理员！")
                }
              ).catch(res => {  // 错误处理
                  console.log(res.data.res)
                  console.log("user_fail")
              })
          }
        }
      ).catch(res => {  // 错误处理
          console.log(res.data.res)
          console.log("user_fail")
      })
    }

    return (
      <div className='Page'>
        <div className='PageHeader'>
          <Header />
        </div>
        <div className='Right'>
          {/* <UserBlock /> */}
        </div>
        <div className='Side'>
            <Sidebar />
            <div className='Contain'>
                <Typography>
                    <Title>我的界面</Title>
                    <Divider />

                    <Title level={2} type='secondary'>如何成为管理员？</Title>
                    <Paragraph>
                        成为管理员的规则介绍放在这里。
                    </Paragraph>
                    <Divider />

                    <Title level={2} type='secondary'>成为管理员能做什么？</Title>
                    <Paragraph>
                        成为管理员的任务介绍放在这里。
                    </Paragraph>
                    <Divider />

                    <Title level={2} type='secondary'>成为管理员</Title>
                    <Button type="primary" onClick={become_admin}>成为管理员</Button>
                    <Divider />

                </Typography>
            </div>
        </div>
        </div>
    )
}

export default BecomeAdminPage